-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Add strong typing to document creation #2161
refactor: Add strong typing to document creation #2161
Conversation
56e6c2f
to
709909e
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## develop #2161 +/- ##
===========================================
- Coverage 74.35% 74.10% -0.25%
===========================================
Files 252 252
Lines 25217 25242 +25
===========================================
- Hits 18749 18704 -45
- Misses 5184 5255 +71
+ Partials 1284 1283 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 16 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work Fred!
06aee19
to
39b7b30
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - just have a few small questions/todos for you :)
} | ||
|
||
docs := make([]*Document, len(a)) | ||
for _, v := range a { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: I would suggest refactoring this block (single doc jsonObj) with NewDocFromJSON
so that they both use exactly the same logic. It feels like it would be more maintainable, and it feels strange that they are not doing so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really practical to do so since here we already have a fastjson.Object
and not a []byte
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You would probably want to change NewDocFromJSON
to create a fastjson.Object
and pass that into the shared code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They already share setWithFastJSONObject
found within SetWithJSON
. I don't think it would simplify anything.
client/document_test.go
Outdated
@@ -61,31 +75,31 @@ func TestNewFromJSON(t *testing.T) { | |||
assert.Equal(t, doc.fields["Name"].Type(), LWW_REGISTER) | |||
assert.Equal(t, doc.fields["Age"].Name(), "Age") | |||
assert.Equal(t, doc.fields["Age"].Type(), LWW_REGISTER) | |||
assert.Equal(t, doc.fields["Address"].Name(), "Address") | |||
assert.Equal(t, doc.fields["Address"].Type(), OBJECT) | |||
// assert.Equal(t, doc.fields["Address"].Name(), "Address") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: Why are these commented out? Please either document why, or put them back :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because in develop it used to create a doc with a sub object which we currently don't support. I should probably just remove the commented code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see my bad :) Thanks for removing them
tests/gen/gen_auto_test.go
Outdated
@@ -1352,7 +1352,7 @@ func TestAutoGenerate_IfColDefinitionsAreValid_ShouldGenerate(t *testing.T) { | |||
Kind: client.FieldKind_STRING, | |||
}, | |||
{ | |||
Name: "owner", | |||
Name: "owner_id", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: This change seems wrong, and I can't spot anything in the PR description. Why has this changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internally the relationship is set on owner_id
and not owner
. For this test to work properly it has to be owner_id
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit confused about this one too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we define a schema, in the SDL only owner
would be defined but internally we also define owner_id
and this is the field that hold the foreign docID. For this test, the code will look specifically for owner_id
to set the foreign docID to. It previously worked before but was accidental and probably a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct though - Kind
is client.FieldKind_FOREIGN_OBJECT
, but foo_id
fields should be of kind INTERNAL_ID
IIRC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed it to be representative of what it would be.
{
Name: "owner_id",
Kind: client.FieldKind_DocKey,
RelationType: client.Relation_Type_INTERNAL_ID,
}
tests/integration/mutation/update/field_kinds/one_to_many/with_alias_test.go
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - Thanks a bunch Fred :)
I mentioned this to Shahzad - his rename PR seemed to touch a lot of the lines that this PR does, strongly suggest checking in with him before merging if you guys haven't already.
Thanks Andy! And yes we have discussed it. He will merge first :) |
1b8d13f
to
6da093a
Compare
6da093a
to
30f2e6a
Compare
## Relevant issue(s) Resolves sourcenetwork#935 Resolves sourcenetwork#1703 ## Description This PR adds strong document typing to document creation by using the field descriptions to determine Go types. Datetime is now properly supported and formatting is enforced. Note that a lot of docIDs have changed as a result of this refactor.
## Relevant issue(s) Resolves sourcenetwork#935 Resolves sourcenetwork#1703 ## Description This PR adds strong document typing to document creation by using the field descriptions to determine Go types. Datetime is now properly supported and formatting is enforced. Note that a lot of docIDs have changed as a result of this refactor.
Relevant issue(s)
Resolves #935
Resolves #1703
Description
This PR adds strong document typing to document creation by using the field descriptions to determine Go types. Datetime is now properly supported and formatting is enforced.
Note that a lot of docIDs have changed as a result of this refactor.
Tasks
How has this been tested?
make test
Specify the platform(s) on which this was tested: